import {createRouter, createWebHistory} from 'vue-router'
import i18n from '@/lang'

const t = i18n.global.t;

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      meta: {title: 'home'},
      redirect: '/lottery',
      // component: () => import('@views/home.vue')
    },
    {
      path: '/lottery',
      name: 'lottery',
      meta: {title: 'lottery.text'},
      component: () => import('@views/lottery.vue')
    },
  ]
});

router.beforeEach(function (to, from, next) {
  const meta = to.meta;
  const title = meta.title;
  if (title) {
    document.title = t(title);
  }
  next();
});

export default router
